package com.etc.service.impl;

import com.etc.dao.Movie_cinemaDao;
import com.etc.entity.Movie_cinema;
import com.etc.service.Movie_cinema_relationService;
import com.etc.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/5/21.
 */
@Service
public class Movie_cinema_relationServiceImpl implements Movie_cinema_relationService {
    @Autowired
    Movie_cinemaDao mc;

    @Override
    public PageData<Movie_cinema> getCinemaByPage(int page, int pageSize, String content) {
        int pageIndex=0;
        if(page>=1){
            pageIndex=page-1;
        }
        Pageable pageable = new PageRequest(pageIndex,pageSize);
        Page page1= mc.findByLike(content,pageable);
        PageData<Movie_cinema> pd = new PageData<Movie_cinema>(page1.getContent(), (int) page1.getTotalElements(),pageSize,page);

        List<Movie_cinema> list=pd.getData();
       list.forEach(System.out::println);
        ArrayList<Movie_cinema> list1 = new ArrayList<>();
        for (int i=0;i<list.size();i++){
            if (list.get(i).getMname()!=null){
                list1.add(list.get(i));
            }
        }

        pd.setData(list1);

        pd.setCount(list1.size());
        return pd;
    }
}
